import request from '@/utils/request'
import method from '@/utils/config'

const urlPrefix = 'crm/'

// 请求路径
const invoiceApi = {
  // 按条件分页查询
  listByParamsForTable: urlPrefix + 'invoice/listByParamsForTable',
  // 新增发票
  saveHasKey: urlPrefix + 'invoice/saveHasKey',
  // 修改发票
  updateByPrimaryKeySelective: urlPrefix + 'invoice/updateByPrimaryKeySelective',
  // 根据id查询发票
  selectByPrimaryKey: urlPrefix + 'invoice/selectByPrimaryKey',
  // 更改开票状态
  changeInvoiceStatus: urlPrefix + 'invoice/changeInvoiceStatus',
  // 重置开票状态
  resetInvoiceStatus: urlPrefix + 'invoice/resetInvoiceStatus',
  // 根据id批量删除发票
  deleteBatchByIds: urlPrefix + 'invoice/removeBatch',
  // 修改发票负责人
  changeOwnerUser: urlPrefix + 'invoice/changeOwnerUser'
}

/**
 * 分页按条件查询
 * @param page 当前页数
 * @param limit 每页条数
 * @param data 条件对象
 * @returns {*}
 */
export function listByParamsForTable(queryParams) {
  return request({
    url: invoiceApi.listByParamsForTable,
    method: method.POST,
    data: queryParams
  })
}

/**
 * 保存发票
 * @param data 发票数据
 * @returns {*}
 */
export function saveHasKey(data) {
  return request({
    url: invoiceApi.saveHasKey,
    method: method.POST,
    data
  })
}

/**
 * 修改发票
 * @param data
 * @returns {*}
 */
export function updateByPrimaryKeySelective(data) {
  return request({
    url: invoiceApi.updateByPrimaryKeySelective,
    method: method.PUT,
    data
  })
}

/**
 * 根据id查询发票
 * @param invoiceId 发票id
 * @returns {*}
 */
export function selectByPrimaryKey(invoiceId) {
  return request({
    url: invoiceApi.selectByPrimaryKey + `?invoiceId=${invoiceId}`,
    method: method.GET
  })
}

/**
 * 根据id批量删除
 * @param ids id集合
 * @returns {AxiosPromise}
 */
export function deleteBatchByIds(ids) {
  return request({
    url: invoiceApi.deleteBatchByIds + `?ids=${ids}`,
    method: method.DELETE
  })
}
